home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / src / drivers.c < prev    next >
C/C++ Source or Header  |  1994-07-16  |  15KB  |  731 lines

  1. #include <stdio.h>
  2. #include "vogl.h"
  3. #include "vodevice.h"
  4.  
  5. /* ---------------------------------------------------------------------
  6.  * Prototypes:
  7.  */
  8. #ifdef __PROTOTYPE__
  9. static void getdev(char *);                            /* drivers.c       */
  10. #else
  11. static void getdev();                                  /* drivers.c       */
  12. #endif
  13.  
  14. /* ---------------------------------------------------------------------
  15.  * Driver Prototypes:
  16.  */
  17. #ifdef __PROTOTYPE__
  18.  
  19. #ifdef AMIGA
  20. void _AMIGA_devcpy(void);                              /* amiga.c         */
  21. #endif
  22.  
  23. #ifdef apollo
  24. int _APOLLO_devcpy(void);                              /* apollo.c        */
  25. #endif
  26.  
  27. #ifdef CGA
  28. int _cga_devcpy(void);                                 /* cga.c           */
  29. #endif
  30.  
  31. #ifdef DECX11
  32. int _DECX11_devcpy(void);                              /* decX11.c        */
  33. #endif
  34.  
  35. #ifdef DXY
  36. int _DXY_devcpy(void);                                 /* hpdxy.c         */
  37. #endif
  38.  
  39. #ifdef EGA
  40. int _ega_devcpy(void);                                 /* ega.c           */
  41. #endif
  42.  
  43. #ifdef GRX
  44. int _grx_devcpy(void);                                 /* grx.c           */
  45. #endif
  46.  
  47. #ifdef HERCULES
  48. #endif
  49.  
  50. #ifdef HGC
  51. int _hgc_devcpy(void);                                 /* hgc.c           */
  52. #endif
  53.  
  54. #ifdef HPGL
  55. int _HPGL_A1_devcpy(void);                             /* hpdxy.c         */
  56. int _HPGL_A2_devcpy(void);                             /* hpdxy.c         */
  57. int _HPGL_A3_devcpy(void);                             /* hpdxy.c         */
  58. int _HPGL_A4_devcpy(void);                             /* hpdxy.c         */
  59. #endif
  60.  
  61. #ifdef NeXT
  62. int _NeXT_devcpy(void);                                /* NeXT.c          */
  63. #endif
  64.  
  65. #ifdef POSTSCRIPT
  66. int _CPS_devcpy(void);                                 /* ps.c            */
  67. int _PS_devcpy(void);                                  /* ps.c            */
  68. int _PSP_devcpy(void);                                 /* ps.c            */
  69. int _PCPS_devcpy(void);                                /* ps.c            */
  70. int _LASER_devcpy(void);                               /* ps.c            */
  71. #endif
  72.  
  73. #ifdef SIGMA
  74. int _sigma_devcpy(void);                               /* sigma.c         */
  75. #endif
  76.  
  77. #ifdef SUN
  78. int _SUN_devcpy(void);                                 /* sun.c           */
  79. #endif
  80.  
  81. #ifdef TEK
  82. int _TEK_devcpy(void);                                 /* tek.c           */
  83. #endif
  84.  
  85. #ifdef VGA
  86. int _vga_devcpy(void);                                 /* vga.c           */
  87. #endif
  88.  
  89. #ifdef X11
  90. int _X11_devcpy(void);                                 /* X11.c           */
  91. #endif
  92.  
  93. #endif    /* __PROTOTYPE__ */
  94.  
  95. /* ---------------------------------------------------------------------
  96.  * Local Variables:
  97.  */
  98. static FILE    *fp        = stdout;
  99. static int     allocated = 0;
  100. struct vdev     vdevice;
  101.  
  102. /* --------------------------------------------------------------------- */
  103.  
  104. /* device-independent function routines */
  105.  
  106. /*
  107.  * voutput
  108.  *
  109.  *    redirect output - only for postscript, hpgl (this is not a feature)
  110.  */
  111. void voutput(char *path)
  112. {
  113. char    buf[128];
  114.  
  115. if ((fp = fopen(path, "w")) == (FILE *)NULL) {
  116.     sprintf(buf, "voutput: couldn't open %s", path);
  117.     verror(buf);
  118.     }
  119. }
  120.  
  121. /* ------------------------------------------------------------------------ */
  122.  
  123. /*
  124.  * _voutfile
  125.  *
  126.  *    return a pointer to the current output file - designed for internal
  127.  * use only.
  128.  */
  129. FILE * _voutfile(void)
  130. {
  131. return(fp);
  132. }
  133.  
  134. /* ------------------------------------------------------------------------ */
  135.  
  136. /*
  137.  * verror
  138.  *
  139.  *    print an error on the graphics device, and then exit. Only called
  140.  * for fatal errors. We assume that stderr is always there.
  141.  *
  142.  */
  143. void verror(char *str)
  144. {
  145. if (vdevice.initialised)
  146. gexit();
  147.  
  148. fprintf(stderr, "%s\n", str);
  149. exit(1);
  150. }
  151.  
  152. /* ------------------------------------------------------------------------ */
  153.  
  154. /*
  155.  * gexit
  156.  *
  157.  *    exit the vogl/vogle system
  158.  *
  159.  */
  160. void gexit(void)
  161. {
  162. if (!vdevice.initialised)
  163. verror("gexit: vogl not initialised");
  164.  
  165. (*vdevice.dev.Vexit)();
  166.  
  167. vdevice.devname = (char *)NULL;
  168. vdevice.initialised = 0;
  169. fp = stdout;
  170. }
  171.  
  172. /* ------------------------------------------------------------------------ */
  173.  
  174. /*
  175.  * getdev
  176.  *
  177.  *    get the appropriate device table structure
  178.  */
  179. static void getdev(char *device)
  180. {
  181.  
  182. #ifdef AMIGA
  183. if      (strncmp(device,"amiga",5) == 0) _AMIGA_devcpy();
  184. else if (strncmp(device,"AMIGA",5) == 0) _AMIGA_devcpy();
  185. else
  186. #endif
  187. #ifdef SUN
  188. if (strncmp(device, "sun", 3) == 0)   _SUN_devcpy();
  189. else
  190. #endif
  191. #ifdef X11
  192. if (strncmp(device, "X11", 3) == 0)   _X11_devcpy();
  193. else
  194. #endif
  195. #ifdef DECX11
  196. if (strncmp(device, "decX11", 6) == 0) _DECX11_devcpy();
  197. else
  198. #endif
  199. #ifdef NeXT
  200. if (strncmp(device, "NeXT", 4) == 0)    _NeXT_devcpy();
  201. else
  202. #endif
  203. #ifdef POSTSCRIPT
  204. if (strncmp(device, "postscript", 10) == 0) {
  205.     _PS_devcpy();
  206.     }
  207. else
  208. if (strncmp(device, "ppostscript", 11) == 0) {
  209.     _PSP_devcpy();
  210.     }
  211. else
  212. #endif
  213. #ifdef HPGL
  214. if (strncmp(device, "hpgla1", 6) == 0)      _HPGL_A1_devcpy();
  215. else if (strncmp(device, "hpgla3", 6) == 0) _HPGL_A3_devcpy();
  216. else if (strncmp(device, "hpgla4", 6) == 0) _HPGL_A4_devcpy();
  217. else if (strncmp(device, "hpgla2", 6) == 0 || strncmp(device, "hpgl", 4) == 0)
  218. _HPGL_A2_devcpy();
  219. else
  220. #endif
  221. #ifdef DXY
  222. if (strncmp(device, "dxy", 3) == 0)         _DXY_devcpy();
  223. else
  224. #endif
  225. #ifdef TEK
  226. if (strncmp(device, "tek", 3) == 0)         _TEK_devcpy();
  227. else
  228. #endif
  229. #ifdef HERCULES
  230. if (strncmp(device, "hercules", 8) == 0)     _hgc_devcpy();
  231. else
  232. #endif
  233. #ifdef CGA
  234. if (strncmp(device, "cga", 3) == 0)          _cga_devcpy();
  235. else
  236. #endif
  237. #ifdef EGA
  238. if (strncmp(device, "ega", 3) == 0)          _ega_devcpy();
  239. else
  240. #endif
  241. #ifdef VGA
  242. if (strncmp(device, "vga", 3) == 0)          _vga_devcpy();
  243. else
  244. #endif
  245. #ifdef SIGMA
  246. if (strncmp(device, "sigma", 5) == 0)        _sigma_devcpy();
  247. else
  248. #endif
  249. {
  250.     if(!device || *device == 0)
  251.     fprintf(stderr,
  252.        "vogl: expected the enviroment variable VDEVICE to be set to the desired device.\n");
  253.     else fprintf(stderr, "vogl: %s is an invalid device type\n", device);
  254.  
  255.     fprintf(stderr, "The devices compiled into this library are:\n");
  256. #ifdef SUN
  257.     fprintf(stderr, "sun\n");
  258. #endif
  259. #ifdef AMIGA
  260.     fprintf(stderr,"amiga\n");
  261. #endif
  262. #ifdef X11
  263.     fprintf(stderr, "X11\n");
  264. #endif
  265. #ifdef DECX11
  266.     fprintf(stderr, "decX11\n");
  267. #endif
  268. #ifdef NeXT
  269.     fprintf(stderr, "NeXT\n");
  270. #endif
  271. #ifdef POSTSCRIPT
  272.     fprintf(stderr, "postscript\n");
  273.     fprintf(stderr, "ppostscript\n");
  274. #endif
  275. #ifdef HPGL
  276.     fprintf(stderr, "hpgla1\n");
  277.     fprintf(stderr, "hpgla2 (or hpgl)\n");
  278.     fprintf(stderr, "hpgla3\n");
  279.     fprintf(stderr, "hpgla4\n");
  280. #endif
  281. #ifdef DXY
  282.     fprintf(stderr, "dxy\n");
  283. #endif
  284. #ifdef TEK
  285.     fprintf(stderr, "tek\n");
  286. #endif
  287. #ifdef HERCULES
  288.     fprintf(stderr, "hercules\n");
  289. #endif
  290. #ifdef CGA
  291.     fprintf(stderr, "cga\n");
  292. #endif
  293. #ifdef EGA
  294.     fprintf(stderr, "ega\n");
  295. #endif
  296. #ifdef VGA
  297.     fprintf(stderr, "vga\n");
  298. #endif
  299. #ifdef SIGMA
  300.     fprintf(stderr, "sigma\n");
  301. #endif
  302.     exit(1);
  303.     }
  304. }
  305.  
  306. /* ------------------------------------------------------------------------ */
  307.  
  308. /*
  309.  * vinit
  310.  *
  311.  *     Just set the device name. ginit and winopen are basically
  312.  * the same as the VOGLE the vinit function.
  313.  *
  314.  */
  315. void vinit(char *device)
  316. {
  317. vdevice.devname = device;
  318. }
  319.  
  320. /* ------------------------------------------------------------------------ */
  321.  
  322. /*
  323.  * winopen
  324.  *
  325.  *    use the more modern winopen call (this really calls ginit),
  326.  * we use the title if we can
  327.  */
  328. long winopen(char *title)
  329. {
  330.  
  331. vdevice.wintitle = title;
  332.  
  333. ginit();
  334.  
  335. return(1L);
  336. }
  337.  
  338. /* ------------------------------------------------------------------------ */
  339.  
  340. /*
  341.  * ginit
  342.  *
  343.  *    by default we check the environment variable, if nothing
  344.  * is set we use the value passed to us by the vinit call.
  345.  */
  346. void ginit(void)
  347. {
  348. char    *dev= NULL;
  349. int    i;
  350.  
  351.  
  352. if (vdevice.devname == (char *)NULL) {
  353.     if ((dev = getenv("VDEVICE")) == (char *)NULL) getdev("");
  354.     else                                           getdev(dev);
  355.     }
  356. else                                               getdev(vdevice.devname);
  357.  
  358. if (vdevice.initialised) gexit();
  359.  
  360. if (!allocated) {
  361.     allocated              = 1;
  362.     vdevice.transmat       = (Mstack *)vallocate(sizeof(Mstack));
  363.     vdevice.transmat->back = (Mstack *)NULL;
  364.     vdevice.attr           = (Astack *)vallocate(sizeof(Astack));
  365.     vdevice.attr->back     = (Astack *)NULL;
  366.     vdevice.viewport